package _0816;

import java.io.*;
import java.util.Scanner;

public class text2 {
    public static void main(String[] args) {
        System.out.println("欢迎注册");
        System.out.println("请输入用户名");
        String name = new Scanner(System.in).next();
        System.out.println("请输入密码");
        String pwd = new Scanner(System.in).next();
        System.out.println("请输入昵称");
        String nick = new Scanner(System.in).next();
        System.out.println("请输入年龄");
        int age = new Scanner(System.in).nextInt();
        User user = new User(name, age, pwd, nick);
        File file = new File(name + ".obj");
        if (file.exists()) {
            System.out.println("用户已存在");
        } else {
            try {
                FileOutputStream fos = new FileOutputStream(file);
                ObjectOutputStream oos = new ObjectOutputStream(fos);
                oos.writeObject(user);
                System.out.println("注册成功");
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}


